package com.example.demo.handler;

import com.example.demo.utils.ResponseResult;
import com.fasterxml.jackson.databind.ObjectMapper;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import org.springframework.security.core.Authentication;
import org.springframework.security.core.AuthenticationException;

import java.io.IOException;

public class MyLogoutFailedHandler {
    public void invoke(HttpServletRequest request, HttpServletResponse response, Authentication authentication, AuthenticationException e) throws IOException {
        response.setStatus(HttpServletResponse.SC_BAD_REQUEST);
        response.setContentType("application/json;charset=UTF-8");
        ResponseResult<String> result = ResponseResult.success(e.getMessage());
        response.getWriter().write(new ObjectMapper().writeValueAsString(result));
    }
}
